<?php

namespace app\admin\controller\user;

use app\common\controller\AdminController;
use app\common\service\finance\WithdrawalAudit;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use think\App;

/**
 * @ControllerAnnotation(title="user_withdraw")
 */
class Withdraw extends AdminController
{

    use \app\admin\traits\Curd;

    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->model = new \app\admin\model\user\UserWithdraw();
        
    }

    public function index()
    {
        if ($this->request->isAjax()) {
            if (input('selectFields')) {
                return $this->selectList();
            }
            list($page, $limit, $where) = $this->buildTableParames();
            $data = \app\common\service\finance\Withdraw::list($page, $limit, $where);
            return json($data);
        }
        return $this->fetch();
    }

    /**
     * Author:Yingbo Sun
     * 提现后台审核 不通过
     * @param $id
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function fail($id)
    {
        $row = $this->model->whereIn('id', $id)->select();
        $row->isEmpty() && $this->error('数据不存在');
        try {
            $data = WithdrawalAudit::failWith($id);
        } catch (\Exception $e) {
            $this->error('审核失败');
        }
        if ($data['code'] == 200){
            return json(['code' => 0,'msg'=>'操作成功']);
        }else{
            return json(['code' => 1,'msg'=>'操作失败']);

        }
    }


    /**
     * Author:Yingbo Sun
     * 提现审核 通过
     * @param $id
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function pass($id)
    {
        $row = $this->model->whereIn('id', $id)->select();
        $row->isEmpty() && $this->error('数据不存在');
        try {
            $data = WithdrawalAudit::pass($id);
        } catch (\Exception $e) {
            $this->error('审核失败');
        }
        if ($data['code'] == 200){
            return json(['code' => 0,'msg'=>'操作成功']);
        }else{
            return json(['code' => 1,'msg'=>'操作失败']);

        }
//        return json($data);
    }




}